/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author The Lunatics
 */
@Entity
@Table(name = "purchases")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Purchases.findAll", query = "SELECT p FROM Purchases p"),
    @NamedQuery(name = "Purchases.findByTransactionId", query = "SELECT p FROM Purchases p WHERE p.transactionId = :transactionId"),
    @NamedQuery(name = "Purchases.findByDate", query = "SELECT p FROM Purchases p WHERE p.date = :date"),
    @NamedQuery(name = "Purchases.findByNumberOfUnits", query = "SELECT p FROM Purchases p WHERE p.numberOfUnits = :numberOfUnits")})
public class Purchases implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "Transaction_Id")
    private Integer transactionId;
    @Basic(optional = false)
    @NotNull
    @Column(name = "Date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date date;
    @Column(name = "Number_Of_Units")
    private Integer numberOfUnits;
    @JoinColumns({
        @JoinColumn(name = "User", referencedColumnName = "User_Id"),
        @JoinColumn(name = "Account", referencedColumnName = "Account_Number")})
    @ManyToOne
    private UserHasAccount userHasAccount;
    @JoinColumn(name = "Advertisement", referencedColumnName = "Advertisement_Id")
    @ManyToOne
    private Advertisements advertisement;

    public Purchases() {
    }

    public Purchases(Integer transactionId) {
        this.transactionId = transactionId;
    }

    public Purchases(Integer transactionId, Date date) {
        this.transactionId = transactionId;
        this.date = date;
    }

    public Integer getTransactionId() {
        return transactionId;
    }

    public void setTransactionId(Integer transactionId) {
        this.transactionId = transactionId;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public Integer getNumberOfUnits() {
        return numberOfUnits;
    }

    public void setNumberOfUnits(Integer numberOfUnits) {
        this.numberOfUnits = numberOfUnits;
    }

    public UserHasAccount getUserHasAccount() {
        return userHasAccount;
    }

    public void setUserHasAccount(UserHasAccount userHasAccount) {
        this.userHasAccount = userHasAccount;
    }

    public Advertisements getAdvertisement() {
        return advertisement;
    }

    public void setAdvertisement(Advertisements advertisement) {
        this.advertisement = advertisement;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (transactionId != null ? transactionId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Purchases)) {
            return false;
        }
        Purchases other = (Purchases) object;
        if ((this.transactionId == null && other.transactionId != null) || (this.transactionId != null && !this.transactionId.equals(other.transactionId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.Purchases[ transactionId=" + transactionId + " ]";
    }
    
}
